

$(function () {
    //getTreeData();
});

var _selectSuccessLisentner;
var _cheched_node_ids;
function getTreeData(selectSuccessLisentner,checkIds) {
    $.ajax({
        type: "GET",
        headers:window.getRequestHears(true),
        url: window.API_SERVER_URL + "aipark/area/tree",
        success: function (tree) {
            loadTree(tree);
        }
    });
    _selectSuccessLisentner = selectSuccessLisentner;
    _cheched_node_ids = checkIds;
}

function loadTree(tree) {
    $('#jstree').jstree({
        'core': {
            'data': tree,
            'state':{"opened":true}
        },
        "plugins": ["search", "checkbox"],
        "checkbox": {
            "keep_selected_style": false,//是否默认选中
            "three_state": true,//父子级别级联选择
            "tie_selection": false
        }
    }).on('loaded.jstree', function(e, data){
        data.instance.open_all(-1);
        if(_cheched_node_ids){
            if(typeof (_cheched_node_ids)=='string'){
                data.instance.check_node(_cheched_node_ids.split(','));
            }else{
                data.instance.check_node(_cheched_node_ids);
            }
        }

    });
    //$('#jstree').jstree().open_all();
}

function selectSuccess() {
    var ref = $('#jstree').jstree(true);
    var nodes = ref.get_checked(true);  //
    if(_selectSuccessLisentner){
        _selectSuccessLisentner(nodes);
    }
}

